home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4746 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  35 lines

  1. Newsgroups: comp.lang.c++
  2. Path: cs.vu.nl!jalten
  3. From: jalten@cs.vu.nl (Alten JP)
  4. Subject: Re: random number in C++
  5. Nntp-Posting-Host: kits.cs.vu.nl
  6. References: <4eoh03$6jb@pacemaker.cts>
  7. Sender: news@cs.vu.nl
  8. Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
  9. Date: Wed, 31 Jan 1996 23:09:58 GMT
  10. X-Newsreader: TIN [version 1.2 PL2]
  11. Message-ID: <DM2J0M.78J.0.-s@cs.vu.nl>
  12.  
  13. Brian A. Bucher (babucher@mtu.edu) wrote:
  14.  
  15. : Is there _ANY_ way to get a truly random number in a C++ program?
  16. : rand and srand do not generate random numbers, they generate
  17. : pseudo-random numbers, which is what I don't need.
  18.  
  19. Get the date and time, cast them to a long,
  20. divide them by the number of bytes available on C:, 
  21. add the number of printer ports and the state of COM1 (if on a PC),
  22. subtract the number of ticks it took to get that information
  23. and pump this into srand. Now ask the user to close his/her
  24. eyes and try to hit any key (or a number of keys) on the keyboard
  25. and take seven as the random number.
  26.  
  27. Always works for me.
  28.  
  29. Jelle Paul
  30.  
  31. +-------------------------------------------------------+
  32. | Jelle Paul Alten                |   jalten@cs.vu.nl   |
  33. | Vrije Universiteit Amsterdam    |                     |
  34. +-------------------------------------------------------+
  35.